#include "gamecontroller.h"
#include "gameconfig.h"
#include <QSound>

GameController *GameController::s_instance = nullptr;
GameController::GameController()
    : m_mainScene(nullptr),
      m_levelScene(nullptr),
      m_gameScene(nullptr)
{

}

GameController::~GameController()
{
//    if(nullptr != s_instance)
//        delete s_instance;

//    if(nullptr != m_mainScene)
//        delete m_mainScene;
//    if(nullptr != m_levelScene)
//        delete m_levelScene;
//    if(nullptr != m_gameScene)
//        delete m_gameScene;
}

GameController *GameController::getInstance()
{
    if (s_instance == nullptr)
    {
        s_instance = new GameController;
    }
    return s_instance;
}

void GameController::initMainScene(MainScene *scene)
{
    m_mainScene = scene;
}

void GameController::showMainScene()
{
    if(nullptr != m_mainScene)
    {
        m_mainScene->show();
//        m_mainScene->setGeometry(m_curGeometry);
        m_mainScene->move(m_curPos);
    }
}

void GameController::hideMainScene()
{
    if (nullptr != m_mainScene)
    {
        m_mainScene->hide();
//        m_curGeometry = m_mainScene->geometry();
        m_curPos = m_mainScene->pos();
    }
}

void GameController::showLevelScene()
{
    if (nullptr == m_levelScene)
    {
        m_levelScene = new LevelScene();
    }
//    m_levelScene->setGeometry(m_curGeometry);
    m_levelScene->move(m_curPos);
    m_levelScene->show();
}

void GameController::hideLevelScene()
{
    if (nullptr != m_levelScene)
    {
        m_levelScene->hide();
//        m_curGeometry = m_levelScene->geometry();
        m_curPos = m_levelScene->pos();
    }
}

void GameController::showGameScene(int level)
{
    if (nullptr == m_gameScene)
    {
        m_gameScene = new GameScene(level);
    }
//    m_gameScene->setGeometry(m_curGeometry);
    m_gameScene->move(m_curPos);
    m_gameScene->show();
}

void GameController::hideGameScene()
{
    if (nullptr != m_gameScene)
    {
        m_gameScene->hide();
//        m_curGeometry = m_gameScene->geometry();
        m_curPos = m_gameScene->pos();
    }
}

void GameController::deleteGameScene()
{
    if (nullptr != m_gameScene)
    {
//        m_curGeometry = m_gameScene->geometry();
        m_curPos = m_gameScene->pos();
        delete m_gameScene;
    }
    m_gameScene = nullptr;
}

void GameController::playStartSound()
{
    QSound::play(SOUND_TAP_BUTTON);
}

void GameController::playBackSound()
{
    QSound::play(SOUND_BACK_BUTTON);
}

void GameController::playFlipCoinSound()
{
    QSound::play(SOUND_COIN_FLIP);
}

void GameController::playWinSound()
{
    QSound::play(SOUND_LEVEL_WIN);
}
